package views;

import java.util.Iterator;

import answers.IAnswer;
import answers.Response;
import models.SurveyResultsModel;
import mvc.AbstractView;
import mvc.IController;

public class SurveyResultsView extends AbstractView
{
	public SurveyResultsView(IController controller, SurveyResultsModel model)
	{
		super(controller);
		itsSurveyResults = model;
	}

	@Override
	public void onInputString(String str)
	{	
		itsIController.onAction(str);
	}

	@Override
	public void update()
	{
		if(itsSurveyResults.getGradeMode())
		{
			System.out.println(itsSurveyResults.getCaption());
		}
		else
		{
			System.out.println("Survey Status: " + itsSurveyResults.getStatus());
			System.out.println("Taken by:" + itsSurveyResults.getFirstName() + " " + itsSurveyResults.getLastName());
			String s = new String("");
			s += "Survey Results for " + itsSurveyResults.getName() + "\n";
			Iterator<Response> iter = itsSurveyResults.itsResponse.iterator();
			int i = 1;
			while(iter.hasNext())
			{
				IAnswer answer = iter.next().getItsIAnswer();
				s += i + ". " + answer.getText() + "\n";
				++i;
			}
			System.out.println(s);
			System.out.println("Summary:");
			System.out.println("correct: " + itsSurveyResults.getCorrect());
			System.out.println("wrong: " + itsSurveyResults.getWrong());
			System.out.println("total score: " + itsSurveyResults.getScore() + "/" + itsSurveyResults.getMaxScore());
		}
	}
	
	private SurveyResultsModel itsSurveyResults;
}
